package com.cloudptt.api.product.operator;


import com.cloudptt.api.comm.CauseCont;
import com.cloudptt.api.product.func.call.CallAttr;
import com.cloudptt.api.product.pjsua2.service.PjsuaService;
import com.cloudptt.api.product.func.SipOperator;
import com.cloudptt.api.product.log.Log;
import com.hytera.productsdk.R;
import com.mcptt.db.DBAdapter;
import com.mcptt.db.model.AddrInfo;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.RemoteException;
import android.view.Surface;
import android.view.SurfaceView;

import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;

public class CallOperator extends SipOperator
{
	private final static String THIS_FILE = "CallOperator";
	public final static int Audio_Dir_SendOnly = 3;
	public final static int Audio_Dir_RecvOnly = 5;
	public final static int Audio_Dir_Mask = 0xffff;

	public final static int Video_Dir_SendOnly = 0x30000;
	public final static int Video_Dir_RecvOnly = 0x50000;
	public final static int Video_Dir_Mask = 0xffff0000;

//	private boolean isAuthorize_Ptt = false;
//	private boolean isAuthorize_Video = false;

//	protected SipCallSession curCallSession = null;

	private DBAdapter dbOperater = null;
	public CallOperator(Context ctx,DBAdapter dbOperater)
	{
		super(ctx);
		this.dbOperater = dbOperater;
		Log.d(THIS_FILE, "CallOperator");
	}

	public int checkPermission(boolean hasVideo)
	{
		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return result;
		}
		boolean hasMcPTT = checkPublishResult(CallAttr.McType_McPtt);
		boolean hasMcVideo = checkPublishResult(CallAttr.McType_McVideo);
		Log.d(THIS_FILE, "checkPermission hasMcPTT = " + hasMcPTT + " hasMcVideo = " + hasMcVideo +" publishResult = "+ publishResult);
		if(!hasVideo
				&& !hasMcPTT)
		{
			return CauseCont.OperateErr_NoAuthorize_Ptt;
		}
		if(hasVideo
				&& !hasMcVideo)
		{
			return CauseCont.OperateErr_NoAuthorize_Video;
		}
		return CauseCont.OperateCheck_Suc;
	}

	public int makeCall(int callType,String groupNum,boolean hasVideo,boolean isEmergency,String funcNum,String locationStr)
	{
		Log.d(THIS_FILE, "makeCall groupNum = " + groupNum + " hasVideo = " + hasVideo+ " isEmergency = " + isEmergency + " funcNum = " + funcNum + " locationStr = " + locationStr);
		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return result;
		}
		boolean hasMcPTT = checkPublishResult(CallAttr.McType_McPtt);
		boolean hasMcVideo = checkPublishResult(CallAttr.McType_McVideo);
		Log.d(THIS_FILE, "makeCall hasMcPTT = " + hasMcPTT + " hasMcVideo = " + hasMcVideo +" publishResult = "+ publishResult);
		if(!hasVideo
				&& !hasMcPTT)
		{
			return CauseCont.OperateErr_NoAuthorize_Ptt;
		}
		if(hasVideo
				&& !hasMcVideo)
		{
			return CauseCont.OperateErr_NoAuthorize_Video;
		}
		
		
//		Bundle b = new Bundle();
//		b.putBoolean(SipCallSession.OPT_CALL_VIDEO, false );

		try 
		{
			groupNum = AddrInfo.toUrlFromNum(groupNum);
//			called = AddrInfo.toUrlFromNum(called);
			Log.d(THIS_FILE, "makeCall groupNum = " + groupNum );
			result = service.makeCallWithOptions(groupNum, callType, hasVideo,isEmergency,funcNum,locationStr);
			if(CauseCont.OperateCheck_Suc == result)
			{
//				setSpeakerphoneOn(CallAttr.CallType_Group);
			}
			return result;
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
			return CauseCont.OperateCheck_Sys_OperateException;
		}
	}
	
	public int makeSingleCall(int type,String callee,boolean hasVidoe,boolean isEmergency,String funcNum,String locationStr)
	{
		Log.d(THIS_FILE, "makeSingleCall callee = " + callee + " hasVidoe = " + hasVidoe + " isEmergency = " + isEmergency + " funcNum = " + funcNum + " locationStr = " + locationStr);
		callee = AddrInfo.toUrlFromNum(callee);
		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return result;
		}

		boolean hasMcPTT = checkPublishResult(CallAttr.McType_McPtt);
		boolean hasMcVideo = checkPublishResult(CallAttr.McType_McVideo);
		Log.d(THIS_FILE, "makeSingleCall hasMcPTT = " + hasMcPTT + " hasMcVideo = " + hasMcVideo  +" publishResult = "+ publishResult);
		if(!hasVidoe
				&& !hasMcPTT)
		{
			return CauseCont.OperateErr_NoAuthorize_Ptt;
		}
		if(hasVidoe
				&& !hasMcVideo)
		{
			return CauseCont.OperateErr_NoAuthorize_Video;
		}

		try 
		{
			result = service.makeCallWithOptions(callee, type, hasVidoe,isEmergency,funcNum,locationStr);
			if(CauseCont.OperateCheck_Suc == result)
			{
//				setSpeakerphoneOn(CallAttr.CallType_Group);
			}
			return result;
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
			return CauseCont.OperateCheck_Sys_OperateException;
		}
	}

	public int hangupCall(String callIdStr,int statusCode)
	{
		Log.d(THIS_FILE, "hangupCall callIdStr is "+ callIdStr + " statusCode = " + statusCode);

		if(callIdStr == null
				|| callIdStr.equals(CallAttr.DEF_CALL_ID_STR))
		{
			return CauseCont.OperateCheck_Sys_OperateException;
		}

		
		try
		{
			return service.hangup(callIdStr, statusCode);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return CauseCont.OperateCheck_Sys_OperateException;
		}
	}

	public int answerCall(String callIdStr,boolean hasVideo)
	{
		Log.d(THIS_FILE, "answerCall callIdStr = "+ callIdStr  + " hasVideo = "+ hasVideo );
		if(callIdStr == null
				|| callIdStr.equals(CallAttr.DEF_CALL_ID_STR))
		{
			return CauseCont.OperateCheck_Sys_OperateException;
		}
		
		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return result;
		}


		try
		{
			result = service.answer(callIdStr, 200, hasVideo);
			if(CauseCont.OperateCheck_Suc == result)
			{
//				setSpeakerphoneOn(callType);
			}
			return result;
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return CauseCont.OperateCheck_Sys_OperateException;
		}
	}

//	public SurfaceView createCallSurfaceView(Context ctx,boolean isLocal)
//	{
//		if(isLocal)
//		{
//			return ViERenderer.CreateLocalRenderer(ctx);
//		}
//		else
//		{
//			return ViERenderer.CreateRenderer(ctx, true);
//		}
//	}
	
//	public int setVideoWindow(int callId,SurfaceView view,boolean isLocal)
//	{
//		Log.d(THIS_FILE, "answerCall callId = "+ callId + " isLocal = "+ isLocal);
//		if(callId < 0
//				|| callId > 255)
//		{
//			return CauseCont.OperateCheck_Sys_OperateException;
//		}
//
//		int result = checkFirst();
//		if(CauseCont.OperateCheck_Suc != result)
//		{
//			return result;
//		}
//
//		try
//		{
//			SipService.setVideoWindow(callId, view, isLocal);
//			return result;
//		}
//		catch(Exception e)
//		{
//			e.printStackTrace();
//			return CauseCont.OperateCheck_Sys_OperateException;
//		}
//	}

	public int sendFloorMsg(String callIdStr,int type)
	{
		Log.d(THIS_FILE, "sendFloorMsg callIdStr = " + callIdStr + " type = " + type);
		
		if(callIdStr == null
				|| callIdStr.equals(CallAttr.DEF_CALL_ID_STR))
		{
			return CauseCont.OperateCheck_Sys_OperateException;
		}
		
		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return result;
		}

		try
		{
			return service.sendFloorMsg(callIdStr,type);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return CauseCont.OperateCheck_Sys_OperateException;
		}
	}
	
	public int sendTransMsg(String callIdStr,int type,String userId, long recverAudioSsrc, long recverVideoSsrc)
	{
		Log.d(THIS_FILE, "sendTransMsg callIdStr = " + callIdStr + " type = " + type);
		if(callIdStr == null
				|| callIdStr.equals(CallAttr.DEF_CALL_ID_STR))
		{
			return CauseCont.OperateCheck_Sys_OperateException;
		}
		
		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return result;
		}

		try
		{
			return service.sendTransMsg(callIdStr,type,userId,recverAudioSsrc,recverVideoSsrc);
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
			return CauseCont.OperateCheck_Sys_OperateException;
		}
	}
	
	public int sendRecvMsg(String callIdStr,int type,String userId, long recverAudioSsrc, long recverVideoSsrc)
	{
		Log.d(THIS_FILE, "sendRecvMsg callIdStr = " + callIdStr + " type = " + type + " userId = " + userId);
		if(callIdStr == null
				|| callIdStr.equals(CallAttr.DEF_CALL_ID_STR))
		{
			return CauseCont.OperateCheck_Sys_OperateException;
		}
		
		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return result;
		}

		try
		{
			return service.sendRecvMsg(callIdStr,type,userId,recverAudioSsrc,recverVideoSsrc);
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
			return CauseCont.OperateCheck_Sys_OperateException;
		}
	}
	
//	public int negotiateRtpChannel(String callIdStr)
//	{
//		Log.d(THIS_FILE, "negotiateRtpChannel callIdStr = " + callIdStr);
//		if(callIdStr == null
//				|| callIdStr.equals(CallAttr.DEF_CALL_ID_STR))
//		{
//			return CauseCont.OperateCheck_Sys_OperateException;
//		}
//
//		int result = checkFirst();
//		if(CauseCont.OperateCheck_Suc != result)
//		{
//			return result;
//		}
//
//		try
//		{
//			return service.negotiateRtpChannel(callIdStr);
//		}
//		catch(Exception e)
//		{
//			e.printStackTrace();
//			return CauseCont.OperateCheck_Sys_OperateException;
//		}
//	}
//
//	public int negotiateVideoChannel(String callIdStr)
//	{
//		Log.d(THIS_FILE, "negotiateVideoChannel callIdStr = " + callIdStr);
//		if(callIdStr == null
//				|| callIdStr.equals(CallAttr.DEF_CALL_ID_STR))
//		{
//			return CauseCont.OperateCheck_Sys_OperateException;
//		}
//
//		int result = checkFirst();
//		if(CauseCont.OperateCheck_Suc != result)
//		{
//			return result;
//		}
//
//		try
//		{
//			return service.negotiateVideoChannel(callIdStr);
//		}
//		catch(Exception e)
//		{
//			e.printStackTrace();
//			return CauseCont.OperateCheck_Sys_OperateException;
//		}
//	}

	public void ring(Context context,boolean isRing)
	{
		Log.d(THIS_FILE, "ring isRing = " + isRing);
		if(service == null)
		{
			Log.e(THIS_FILE, "service == null ");
			return;
		}
		try
		{
			if(isRing)
			{
				requestWakeLock(context,10);
			}
			service.ring(1,isRing);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	public void requestWakeLock(Context context,long sec) {
		Log.debug(this.getClass(), "requestWakeLock sec = " + sec);
		PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
		if (powerManager != null) {
			boolean screenOn = powerManager.isScreenOn();
			Log.debug(this.getClass(), "requestWakeLock screenOn = " + screenOn);
			if(!screenOn) {
				PowerManager.WakeLock wakeLock = powerManager.newWakeLock(
						PowerManager.SCREEN_BRIGHT_WAKE_LOCK | // 全亮屏模式
								PowerManager.ACQUIRE_CAUSES_WAKEUP, // 强制唤醒
						"msg"
				);
				wakeLock.acquire(sec * 1000L); // 亮屏10秒后自动释放，避免耗电
				wakeLock.release(); // 立即释放锁
			}
		}
	}


	public void answer180(String callIdStr,boolean hasVideo)
	{
		Log.d(THIS_FILE, "ring callIdStr = " + callIdStr + " hasVideo = " + hasVideo);
		if(service == null)
		{
			Log.e(THIS_FILE, "service == null ");
			return;
		}
		try
		{
			service.answer(callIdStr, 180, hasVideo);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	public void updateAudioChannel(int callType,boolean hasVideo)
	{
		Log.d(THIS_FILE, "updateAudioChannel callType = " + callType + " hasVideo = " + hasVideo);
		if(service == null)
		{
			Log.e(THIS_FILE, "service == null ");
			return;
		}
		try
		{
			service.updateAudioChannel(callType,hasVideo);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	public void requestAudioFocus(boolean isSetSnd)
	{
		Log.d(THIS_FILE, "requestAudioFocus isSetSnd = " + isSetSnd);
		try {
			service.requestAudioFocus(isSetSnd);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


//	public void releaseAudioFocus()
//	{
//		Log.d(THIS_FILE, "releaseAudioFocus");
//		try {
//			service.releaseAudioFocus();
//		} catch (RemoteException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//	}
	
	public int opAudioMedia(String callIdStr,int opType)
	{
		Log.d(THIS_FILE, "opAudioMedia callIdStr = " + callIdStr + " opType = " + opType);
		if(callIdStr == null
				|| callIdStr.equals(CallAttr.DEF_CALL_ID_STR))
		{
			return CauseCont.OperateCheck_Sys_OperateException;
		}
		
		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return result;
		}

		try
		{
			return service.opAudioMedia(callIdStr, opType);
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
			return CauseCont.OperateCheck_Sys_OperateException;
		}
	}

	public int sendKeyFrame(String callIdStr)
	{
		Log.d(THIS_FILE, "sendKeyFrame callIdStr = " + callIdStr);
		if(callIdStr == null
				|| callIdStr.equals(CallAttr.DEF_CALL_ID_STR))
		{
			return CauseCont.OperateCheck_Sys_OperateException;
		}

		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return result;
		}

		try
		{
			return service.sendKeyFrame(callIdStr);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return CauseCont.OperateCheck_Sys_OperateException;
		}
	}
	
	public int opVideoMedia(String callIdStr,int opType)
	{
		Log.d(THIS_FILE, "opVideoMedia callIdStr = " + callIdStr + " opType = " + opType);
		if(callIdStr == null
				|| callIdStr.equals(CallAttr.DEF_CALL_ID_STR))
		{
			return CauseCont.OperateCheck_Sys_OperateException;
		}
		
		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return result;
		}

		try
		{
			return service.opVideoMedia(callIdStr, opType);
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
			return CauseCont.OperateCheck_Sys_OperateException;
		}
	}

	public int opVideoStream(String callIdStr,int opType)
	{
		Log.d(THIS_FILE, "opVideoStream callIdStr = " + callIdStr + " opType = " + opType);
		if(callIdStr == null
				|| callIdStr.equals(CallAttr.DEF_CALL_ID_STR))
		{
			return CauseCont.OperateCheck_Sys_OperateException;
		}

		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return result;
		}

		try
		{
			return service.opVideoStream(callIdStr, opType);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return CauseCont.OperateCheck_Sys_OperateException;
		}
	}

	public int switchCamera(String callIdStr)
	{
		Log.d(THIS_FILE, "switchCamera callIdStr = " + callIdStr );
		if(callIdStr == null
				|| callIdStr.equals(CallAttr.DEF_CALL_ID_STR))
		{
			return CauseCont.OperateCheck_Sys_OperateException;
		}

		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return result;
		}

		try
		{
			return service.switchCamera(callIdStr);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return CauseCont.OperateCheck_Sys_OperateException;
		}
	}

	public int opVideoWinShow(String callIdStr,boolean isLocal,boolean isShow)
	{
		Log.d(THIS_FILE, "opVideoWinShow callIdStr = " + callIdStr + " isLocal = " + isLocal +  " isShow = " + isShow);
		if(callIdStr == null
				|| callIdStr.equals(CallAttr.DEF_CALL_ID_STR))
		{
			return CauseCont.OperateCheck_Sys_OperateException;
		}

		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return result;
		}

		try
		{
			return service.opVideoWinShow(callIdStr, isLocal,isShow);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return CauseCont.OperateCheck_Sys_OperateException;
		}
	}

	public int updateCallOptions(int callId, Bundle bundle) {
		Log.d(THIS_FILE, "updateCallOptions callId = " + callId );
		if(callId < 0
				|| callId > 255)
		{
			return CauseCont.OperateCheck_Sys_OperateException;
		}
		
		if (null != service) {
			try {
				return service.updateCallOptions(callId, true,true);
			} catch (RemoteException e) {
				e.printStackTrace();
			}
		}
		return -1;
	}

	public void holdGroupCall(int callId)
	{
		Log.d(THIS_FILE, "holdGroupCall callId = " + callId );
		if(callId < 0
				|| callId > 255)
		{
			return;
		}
//		int callId = 0;
//		if(curCallSession != null)
//		{
//			callId = curCallSession.getCallId();
//		}
		try
		{
			Log.e(THIS_FILE, "doDisconnectCallAction callId is "+ callId);
			service.hold(callId);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	public void destoryCall(String callIdStr)
	{
		Log.d(THIS_FILE, "destoryGroupCall");
		if(service == null) 
		{
			Log.e(THIS_FILE, "service == null ");
			return;
		}
		try
		{
			Log.e(THIS_FILE, "destoryCall ");
//			service.destoryCall(callIdStr);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public void clearAllCalls()
	{
		Log.d(THIS_FILE, "clearAllCalls");
		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return;
		}
		try 
		{
//			service.setSpeakerphoneOn( false );
			service.clearAllCalls();
		} catch (RemoteException e) {
			Log.e(THIS_FILE, "Service can't be called to make the call");
		}
	}
	
	public void clearResourceForCallEnd(String callIdStr)
	{
		Log.d(THIS_FILE, "clearResourceForCallEnd callIdStr = " + callIdStr );
		if(callIdStr == null
				|| callIdStr.equals(CallAttr.DEF_CALL_ID_STR))
		{
			return;
		}
		
		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return;
		}
		try 
		{
//			service.setSpeakerphoneOn( false );
			service.ring(1,false);
			service.clearResourceForCallEnd(callIdStr);
		} catch (RemoteException e) {
			Log.e(THIS_FILE, "Service can't be called to make the call");
		}
	}
	
	public boolean isActiveCall()
	{
		Log.d(THIS_FILE, "isActiveNoIncommingCall");
		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return false;
		}
		try 
		{
			return service.isActiveCall();
		} catch (RemoteException e) {
			Log.e(THIS_FILE, "Service can't be called to make the call");
			return true;
		}
	}
	
	public boolean isIncommingCall()
	{
		Log.d(THIS_FILE, "isIncommingCall");
		int result = checkFirst();
		if(CauseCont.OperateCheck_Suc != result)
		{
			return false;
		}
		try 
		{
			return service.isIncommingCall();
		} catch (RemoteException e) {
			Log.e(THIS_FILE, "Service can't be called to make the call");
			return false;
		}
	}

//	protected void sendSysMsg(String msgStr) 
//	{
//		Log.d(THIS_FILE, "sendSysMsg msgStr is " + msgStr);
//		if (service == null) {
//			Log.e(THIS_FILE, "service is null");
//			return;
//		}
//		try 
//		{
//			service.sendSystemMessage(msgStr);
//		} catch (RemoteException e) {
//			Log.e(THIS_FILE, "Service can't be called to make the call");
//		}
//	}
	
//	private void setSpeakerphoneOn(int callType, boolean isAnswer) throws Exception
//	{
//		MediaState ms = service.getCurrentMediaState();		
//
//		if(!ms.canBluetoothSco)
//		{
//			if(SipCallSession.Call_Group == callType)
//			{
//				service.setSpeakerphoneOn(true);//
//			}
//			else if(SipCallSession.Call_Privacy == callType)
//			{
//				service.setSpeakerphoneOn( (null != config) ? config.isPrivateSpeakerOn() : false );
//			}
//
//			Log.e(THIS_FILE, "setSpeakerphoneOn() : callType=" + callType + ",isAnswer=" + isAnswer);
//		}
//		else if(ms.canBluetoothSco && !ms.isBluetoothScoOn)
//		{
//			service.setBluetoothOn(true);
//		}
//	}
	
//	private void setSpeakerphoneOn(int callType) throws Exception
//	{
////		MediaState ms = service.getCurrentMediaState();		
//
////		if(!ms.canBluetoothSco)
////		{
//			if(CallAttr.CallType_Group == callType)
//			{
////				service.setSpeakerphoneOn(true);
//			}
//			else if(CallAttr.CallType_Webrtc_Single == callType)
//			{
////				boolean isTrue = isPrivateSpeakerOn();
////				Log.e(THIS_FILE, "setSpeakerphoneOn isTrue=" + isTrue);
////				service.setSpeakerphoneOn(true);
//			}
//
//			Log.e(THIS_FILE, "setSpeakerphoneOn() : callType=" + callType);
////		}
////		else if(ms.canBluetoothSco && !ms.isBluetoothScoOn)
////		{
////			service.setBluetoothOn(true);
////		}
//	}
	
//	public void setNoSnd() throws Exception
//	{
//		if(Product.getProductType() == ProductConst.ProductType_NAPP)
//		{
//			return;
//		}
//		Log.e(THIS_FILE, "setNoSnd");
//		service.setNoSnd();
//	}
//	
//	public void setSnd(boolean isMust) throws Exception
//	{
//		if(Product.getProductType() == ProductConst.ProductType_NAPP)
//		{
//			return;
//		}
//		Log.e(THIS_FILE, "setSnd isMust =" + isMust);
//		service.setSnd();
//	}
	
	public void screenAngle(String callIdStr,int angle)
	{
		Log.e(THIS_FILE, "screenAngle callIdStr =" + callIdStr + " angle = " + angle);
//		try {
//			service.screenAngle(callId,angle);
//		} catch (RemoteException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	}

	public String showCallInfosDialog( int callId ){
		
		Log.d(THIS_FILE, "showCallInfosDialog callId = " + callId );
		String info = "";
		if(callId < 0
				|| callId > 255)
		{
			return info;
		}
		
		if( null != service )
    	{
    		try {
				info = service.showCallInfosDialog( callId );
			} catch (RemoteException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    	}
		
		return info;
	}
	
	public String getLocalNatType(){
		String natType="";
		try {
			natType = service.getLocalNatType();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return natType;
	}
	
	public void playWaveFile(final String filePath, final String callIdStr, final int way){
//		try {
//			service.playWaveFile(filePath, callIdStr, way);
//		} catch (RemoteException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	}
	
	public void sendSubscribe(String uri){
		try {
			service.sendSubscribe(uri);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void subcribeConference( String callIdStr, boolean isActive, String sessionId, String groupNum,boolean hasVideo){
		try {
			service.subcribeConference(callIdStr,isActive,sessionId,groupNum,hasVideo);
			if(!isActive)
			{
				String groupId = AddrInfo.toNumFromSipUrl(groupNum);
				dbOperater.resetGroupMembStatus(groupId);
			}
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void onVol(int type)
	{
		try {
			service.onVol(type);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public boolean setSpeakerphoneEnable(boolean enable)
	{
		try {
			return service.setSpeakerphoneEnable(enable);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return enable;
	}
	public boolean setMicrophoneEnable(String callIdStr,boolean enable)
	{
		try {
			if(enable) {
				service.opAudioMedia(callIdStr, CallAttr.OpMedia_Resume);
			}else
			{
				service.opAudioMedia(callIdStr, CallAttr.OpMedia_Pause);
			}
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return enable;
	}
	public void muteCall(String callIdStr,boolean enable)
	{
		Log.d(THIS_FILE, "muteCall callIdStr = " + callIdStr + " enable = " + enable);
		if(callIdStr == null
				|| callIdStr.equals(CallAttr.DEF_CALL_ID_STR))
		{
			return;
		}
		try
		{
//			service.muteCall(callId, isOn);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	
//	public void playWaveFile(final String filePath, final int callId, final int way){
//		try {
//			service.playWaveFile(filePath, callId, way);
//		} catch (RemoteException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//	}

//	public boolean isVidOk(String callIdStr) {
//		try {
//			return PjsuaService.isVidOk(callIdStr);
//		}
//		catch (Exception e)
//		{
//			return false;
//		}
//	}
	public void setSurfaceView(String callIdStr, SurfaceView surfaceInVideo, SurfaceView surfacePreview) {
		PjsuaService.opSetSurfaceView(callIdStr,surfaceInVideo,surfacePreview);
	}
//	public void startPreView(String callIdStr,Surface surface) {
//		PjsuaService.opStartPreView(callIdStr,surface);
//	}
//	public void stopPreView(String callIdStr) {
//		Log.d(THIS_FILE, "stopPreView callIdStr = " + callIdStr );
//		PjsuaService.opStopPreView(callIdStr);
//	}
//
//	public void setRemoteView(String callIdStr,Surface surface){
//		try {
//			PjsuaService.opSetRemoteSurfaceView(callIdStr,surface);
//		}catch (Exception e){
//			e.printStackTrace();
//		}
//	}

	public void setCaptureOrient(int orient){
		try {
			PjsuaService.opSetCaptureOrient(orient);
		}catch (Exception e){
			e.printStackTrace();
		}
	}
}
